package com.blog.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.blog.common.annotation.Log;
import com.blog.common.enums.BusinessType;
import com.blog.system.domain.RoomTime;
import com.blog.system.service.IRoomTimeService;
import com.blog.common.core.controller.BaseController;
import com.blog.common.core.domain.AjaxResult;
import com.blog.common.utils.poi.ExcelUtil;
import com.blog.common.core.page.TableDataInfo;

/**
 * 自习室时间段Controller
 * 
 * @author ruoyi
 * @date 2025-03-13
 */
@Controller
@RequestMapping("/system/time")
public class RoomTimeController extends BaseController
{
    private String prefix = "system/time";

    @Autowired
    private IRoomTimeService roomTimeService;

    @RequiresPermissions("system:time:view")
    @GetMapping()
    public String time()
    {
        return prefix + "/time";
    }

    /**
     * 查询自习室时间段列表
     */
    @RequiresPermissions("system:time:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RoomTime roomTime)
    {
        startPage();
        List<RoomTime> list = roomTimeService.selectRoomTimeList(roomTime);
        return getDataTable(list);
    }

    /**
     * 导出自习室时间段列表
     */
    @RequiresPermissions("system:time:export")
    @Log(title = "自习室时间段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RoomTime roomTime)
    {
        List<RoomTime> list = roomTimeService.selectRoomTimeList(roomTime);
        ExcelUtil<RoomTime> util = new ExcelUtil<RoomTime>(RoomTime.class);
        return util.exportExcel(list, "自习室时间段数据");
    }

    /**
     * 新增自习室时间段
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存自习室时间段
     */
    @RequiresPermissions("system:time:add")
    @Log(title = "自习室时间段", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RoomTime roomTime)
    {
        return toAjax(roomTimeService.insertRoomTime(roomTime));
    }

    /**
     * 修改自习室时间段
     */
    @RequiresPermissions("system:time:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        RoomTime roomTime = roomTimeService.selectRoomTimeById(id);
        mmap.put("roomTime", roomTime);
        return prefix + "/edit";
    }

    /**
     * 修改保存自习室时间段
     */
    @RequiresPermissions("system:time:edit")
    @Log(title = "自习室时间段", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RoomTime roomTime)
    {
        return toAjax(roomTimeService.updateRoomTime(roomTime));
    }

//    /**
//     * 删除自习室时间段
//     */
//    @RequiresPermissions("system:time:remove")
//    @Log(title = "自习室时间段", businessType = BusinessType.DELETE)
//    @PostMapping( "/remove")
//    @ResponseBody
//    public AjaxResult remove(String ids)
//    {
//        return toAjax(roomTimeService.softDeleteRoomTimeByIds(ids));
//    }
}
